﻿using System;
using System.Collections.Generic;
using System.Web;

namespace Manager.CustomerHelper
{
    // 目前不用了
    /// <summary>
    /// 模块删除的权限
    /// </summary>
    public enum RemovedModulePowerType
    {
        CoreOnlineUser_CanDelete,
        CoreOnlineUser_CanEdit,
        CoreOnlineUser_CanAdd,
        CorePassword_CanDelete,
        CorePassword_CanEdit,
        CorePassword_CanAdd,
        CoreConf_CanDelete,
        CoreConf_CanEdit,
        CoreConf_CanAdd,
        CoreLog_CanEdit,
        CoreLog_CanAdd,
        CoreRoleModule_CanDelete,
        CoreRoleModule_CanAdd,
        CoreRoleUser_CanEdit
    }

    public class RemovedModulePowerTypeHelper
    {
        /// <summary>
        /// 字符串转换为RemovedModulePowerType
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public static RemovedModulePowerType String2Power(string text)
        {
            return String2Power(text, false);
        }

        /// <summary>
        /// 字符串转换为RemovedModulePowerType
        /// </summary>
        /// <param name="text"></param>
        /// <param name="ignoreCase"></param>
        /// <returns></returns>
        public static RemovedModulePowerType String2Power(string text, bool ignoreCase)
        {
            return (RemovedModulePowerType)Enum.Parse(typeof(RemovedModulePowerType), text, ignoreCase);
        }

        /// <summary>
        /// RemovedModulePowerType转换为字符串
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static String Power2String(RemovedModulePowerType type)
        {
            return type.ToString();
        }

        /// <summary>
        /// 获取所有权限的名称列表
        /// </summary>
        /// <returns></returns>
        public static string[] GetRemovedModulePowerTypes()
        {
            return Enum.GetNames(typeof(RemovedModulePowerType));
        }

        private static Dictionary<string, List<string>> _removedModulePowerTypeDic = new Dictionary<string, List<string>>();

        /// <summary>
        /// 获得每个模块对应的其他权限名称列表
        /// </summary>
        /// <returns></returns>
        public static List<string> GetRemovedModulePowerTypeDic(string moduleTypeName)
        {
            if (!_removedModulePowerTypeDic.ContainsKey(moduleTypeName))
            {
                _removedModulePowerTypeDic[moduleTypeName] = new List<string>();

                foreach (string otherPower in GetRemovedModulePowerTypes())
                {
                    int underscoreIndex = otherPower.IndexOf('_');
                    if (underscoreIndex >= 0)
                    {
                        string moduleName = otherPower.Substring(0, underscoreIndex);
                        if (moduleName == moduleTypeName)
                        {
                            string powerName = otherPower.Substring(underscoreIndex + 1);
                            _removedModulePowerTypeDic[moduleTypeName].Add(powerName);
                        }
                    }
                }

            }

            return _removedModulePowerTypeDic[moduleTypeName];
        }


    }

}